package com.huatai.datacenter.controller;

import com.alibaba.fastjson.JSONObject;
import com.huatai.common.api.R;
import com.huatai.datacenter.entity.TopicTaskEntity;
import com.huatai.datacenter.service.TopicTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Lion
 * @date 2023/6/2  13:44
 */
@RequestMapping("/topicTask")
@RestController
@Api(value = "主题任务管理",tags = "主题任务管理")
public class TopicTaskController extends BaseController<TopicTaskService, TopicTaskEntity>{

	/**
	 * @author Lion
	 * @description 保存前端数据并启动监听
	 * @param entity
	 * @return com.huatai.common.api.R
	 */
	@ApiOperation("保存主题任务")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "主题任务id", dataType = "long"),
		@ApiImplicitParam(name = "topicName", value = "主题名称", dataType = "String"),
		@ApiImplicitParam(name = "topicTaskName", value = "主题任务名称", dataType = "String"),
		@ApiImplicitParam(name = "clusterId", value = "集群id", dataType = "long"),
		@ApiImplicitParam(name = "clustername", value = "集群名称", dataType = "String"),
		@ApiImplicitParam(name = "modelId", value = "模型id", dataType = "long"),
		@ApiImplicitParam(name = "modelName", value = "模型名称", dataType = "String"),
		@ApiImplicitParam(name = "comments", value = "任务描述", dataType = "String"),
		@ApiImplicitParam(name = "dataTable", value = "表名", dataType = "String"),
		@ApiImplicitParam(name = "groupId", value = "消费组", dataType = "String"),
		@ApiImplicitParam(name = "qualityRule", value = "质量规则", dataType = "String"),
		@ApiImplicitParam(name = "typeMq", value = "消息类型", dataType = "String")
	})
	@RequestMapping("/savaTopicTask")
	public R savaTopicTask(@RequestBody TopicTaskEntity entity){

		this.service.savaTopicTask(entity);
		return R.success("success");
	}

	/**
	 * @author Lion
	 * @description 删除主题任务
	 * @param  data
	 * @return com.huatai.common.api.R
	 */
	@ApiOperation("删除主题任务")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "主题任务id", dataType = "long")
	})
	@RequestMapping("/deleteTopicTask")
	public R savaTopicTask(@RequestBody JSONObject data){

		List list = data.getJSONArray("id");
		this.service.deleteTopicTaskById(list);

		return R.success("success");
	}

	/**
	 * @author Lion
	 * @description 更新主题任务
	 * @param entity
	 * @return com.huatai.common.api.R
	 */
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "主题任务id", dataType = "long"),
		@ApiImplicitParam(name = "topicTaskName", value = "主题任务名称", dataType = "String"),
		@ApiImplicitParam(name = "topicName", value = "主题名称", dataType = "String"),
		@ApiImplicitParam(name = "clusterId", value = "集群id", dataType = "long"),
		@ApiImplicitParam(name = "clustername", value = "集群名称", dataType = "String"),
		@ApiImplicitParam(name = "modelId", value = "模型id", dataType = "long"),
		@ApiImplicitParam(name = "modelName", value = "模型名称", dataType = "String"),
		@ApiImplicitParam(name = "comments", value = "任务描述", dataType = "String"),
		@ApiImplicitParam(name = "dataTable", value = "表名", dataType = "String"),
		@ApiImplicitParam(name = "groupId", value = "消费组", dataType = "String"),
		@ApiImplicitParam(name = "threadId", value = "线程id", dataType = "long")
	})
	@RequestMapping("/updateTopicTask")
	@ApiOperation("更新主题任务")
	public R updateTopicTask(@RequestBody TopicTaskEntity entity){
		this.service.updateTopicTask(entity);
		return R.success("success");
	}

}
